﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utility.Data.DbClient;
using Utility.Extensions;

namespace Utility.DBUtility.DatabaseOperate
{
    /// <summary>
    /// 数据库操作抽象类
    /// </summary>
    public abstract class DbHelperBase: IDbHelper
    {
        /// <summary>
        /// 参数类型
        /// </summary>
        protected DBParameterExtensions.DatabaseType m_DatabaseType;
        /// <summary>
        /// 获取数据库类型
        /// </summary>
        public DBParameterExtensions.DatabaseType DataBaseType
        {
            get { return m_DatabaseType; }
        }
        /// <summary>
        /// 用户编写的SQL、参数前缀符号
        /// </summary>
        protected char m_DataParamterPrefixChar;
        /// <summary>
        /// 变量名前缀
        /// </summary>
        public char DataParamterPrefixChar { get { return m_DataParamterPrefixChar; } }
        /// <summary>
        /// 空参数对象(用于区分DbParameter[]/IDataParameter[])
        /// </summary>
        protected IDataParameter[] m_NullParameter = new List<IDataParameter>().ToArray();
        private string m_ConnectionStringName;
        /// <summary>
        /// (写)数据库连接字符串(web.config来配置)，可以动态更改connectionString支持多数据库. 
        /// </summary>   
        protected string m_WriteConnectionString
        {
            get
            {
                return DBStringManage.Instance.GetDbString(m_ConnectionStringName, DatabaseType.Master);
            }
        }
        /// <summary>
        /// (读)数据库连接字符串(web.config来配置)，可以动态更改connectionString支持多数据库. 
        /// </summary>
        protected string m_ReadConnectonString
        {
            get
            {
                return DBStringManage.Instance.GetDbString(m_ConnectionStringName, DatabaseType.Backup);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="connectionStringName">使用的链接字符串名称</param>
        /// <param name="dataParameterType">数据库参数的类型</param>
        /// <param name="dataParamterPrefixChar">用户编写的SQL、参数前缀符号</param>
        public DbHelperBase(string connectionStringName = "DefaultConnection"
                            , DBParameterExtensions.DatabaseType dataParameterType = DBParameterExtensions.DatabaseType.Oracle
                            , char dataParamterPrefixChar=':')
        {
            m_ConnectionStringName = connectionStringName;
            m_DatabaseType = dataParameterType;
            m_DataParamterPrefixChar = dataParamterPrefixChar;
            //m_WriteConnectionString = DBStringManage.Instance.GetDbString(connectionStringName, DatabaseType.Master);//  ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
            //m_ReadConnectonString = DBStringManage.Instance.GetDbString(connectionStringName, DatabaseType.Backup);// m_WriteConnectionString;
        }
        #region Connection
        private AdoNetObject _AdoNetObject;
        /// <summary>
        /// 事务访问对象
        /// </summary>
        protected AdoNetObject AdoNetObject
        {
            get
            {
                if (string.IsNullOrEmpty(Transactionid))
                {
                    return null;
                }
                else if (null == _AdoNetObject)
                {
                    AdoNetObject adoObject;
                    if (ORMCommData.AdoNetObjects.TryGetValue(Transactionid, out adoObject))
                    {
                        _AdoNetObject = adoObject;
                    }
                }
                return _AdoNetObject;
            }
        }        
        /// <summary>
        /// 事务ID,作为事务开启和关闭的ID号
        /// </summary>
        public string Transactionid
        {
            get;set;
        }

        #region 自动提交事务
        internal AdoNetObject _AutoAdoNetObject;
        /// <summary>
        /// 自动事务访问对象
        /// </summary>
        internal AdoNetObject AutoAdoNetObject
        {
            get
            {
                if (string.IsNullOrEmpty(AutoTransactionid))
                {
                    return null;
                }
                else if (null == _AutoAdoNetObject)
                {
                    AdoNetObject adoObject;
                    if (ORMCommData.AdoNetObjects.TryGetValue(AutoTransactionid, out adoObject))
                    {
                        _AutoAdoNetObject = adoObject;
                    }
                }
                return _AutoAdoNetObject;
            }
        }
        /// <summary>
        /// 自动提交事务ID,作为事务开启和关闭的ID号
        /// </summary>
        internal string AutoTransactionid
        {
            get;set;
        }
        /// <summary>
        /// 当前项目中使用,自动提交事务
        /// </summary>
        /// <returns></returns>
        internal abstract string AutoBeginTransaction(string connectionString = "", IsolationLevel isolationLevel = IsolationLevel.ReadCommitted);
        /// <summary>
        /// 自动提交事务
        /// 提交事务后,将清空链接对象
        /// </summary>
        internal void AutoCommit()
        {
            if (!string.IsNullOrEmpty(AutoTransactionid))
            {
                try
                {
                    AutoAdoNetObject.Commit();
                }
                finally
                {
                    ORMCommData.AdoNetObjects.TryRemove(AutoTransactionid, out _AutoAdoNetObject);
                    _AutoAdoNetObject = null;
                    AutoTransactionid = string.Empty;
                }
            }
        }
        /// <summary>
        /// 自动回滚事务
        /// 回滚事务后,将清空链接对象
        /// </summary>
        internal void AutoRollback()
        {
            if (!string.IsNullOrEmpty(AutoTransactionid))
            {
                try
                {
                    AutoAdoNetObject.Rollback();
                }
                finally
                {
                    ORMCommData.AdoNetObjects.TryRemove(AutoTransactionid, out _AutoAdoNetObject);
                    _AutoAdoNetObject = null;
                    AutoTransactionid = string.Empty;
                }
            }
        }
        #endregion

        /// <summary>
        /// 开启事务, 使用事务必须设定每个Data实例的 Transactionid. 相同的Transactionid 才会在一个事务中提交
        /// 一个Data实例开启事务,相同 Transactionid 的Data实例都将使用到事务
        /// [目前不支持存储过程放入事务中]
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="isolationLevel">事务开启级别</param>
        /// <returns>
        /// 返回事务ID,作为事务开启和关闭的ID号,同时也作为其它Data使用的数据库连接ID与事务ID
        /// </returns>
        public abstract string BeginTransaction(string connectionString = "", IsolationLevel isolationLevel = IsolationLevel.ReadCommitted);
        /// <summary>
        /// 提交事务
        /// 提交事务后,将清空链接对象
        /// </summary>
        public void Commit()
        {
            if (!string.IsNullOrEmpty(Transactionid))
            {
                try
                {
                    AdoNetObject.Commit();                    
                }
                finally
                {
                    ORMCommData.AdoNetObjects.TryRemove(Transactionid, out _AdoNetObject);
                    _AdoNetObject = null;
                    Transactionid = string.Empty;
                }
            }
        }
        /// <summary>
        /// 回滚事务
        /// 回滚事务后,将清空链接对象
        /// </summary>
        public void Rollback()
        {
            if (!string.IsNullOrEmpty(Transactionid))
            {
                try
                {
                    AdoNetObject.Rollback();
                }
                finally
                {
                    ORMCommData.AdoNetObjects.TryRemove(Transactionid, out _AdoNetObject);
                    _AdoNetObject = null;
                    Transactionid = string.Empty;
                }
            }
        }
        #endregion

        #region Exists
        /// <summary>
        /// 判断表是否存在
        /// </summary>
        /// <param name="tableName">需要判断的表名</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public abstract bool ExistsTable(string tableName, string connectionString = "");
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public bool Exists(string strSql, string connectionString = "")
        {
            return Exists(strSql, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public bool Exists(string strSql, params DBParameter[] cmdParms)
        {
            return Exists(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public bool Exists(string strSql, params IDataParameter[] cmdParms)
        {
            return Exists(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <param name="userMasterConnection">使用主数据库进行查询</param>
        /// <returns></returns>
        public bool Exists(string strSql, bool userMasterConnection = false, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Exists(strSql, m_WriteConnectionString, cmdParms);
            }
            return Exists(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <param name="userMasterConnection">使用主数据库进行查询</param>
        /// <returns></returns>
        public bool Exists(string strSql, bool userMasterConnection = false, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Exists(strSql, m_WriteConnectionString, cmdParms);
            }
            return Exists(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public bool Exists(string strSql, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Exists(strSql, connectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public bool Exists(string strSql, string connectionString = "", params IDataParameter[] cmdParms)
        {
            object obj = ExecuteScalar(strSql, connectionString, cmdParms);
            int cmdresult;
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        /// <summary>
        /// 判断指定表指定栏位值是否存在
        /// </summary>
        /// <param name="values">栏位名称/值</param>
        /// <param name="tableName">表名</param>
        /// <param name="userMasterConnection">是否使用主数据库进行查询</param>
        /// <returns></returns>
        public bool Exists(Dictionary<string, object> values, string tableName, bool userMasterConnection)
        {
            if (userMasterConnection)
            {
                return Exists(values, tableName, m_WriteConnectionString);
            }
            return Exists(values, tableName);
        }
        /// <summary>
        /// 判断指定表指定栏位值是否存在
        /// </summary>
        /// <param name="values">栏位名称/值</param>
        /// <param name="tableName">表名</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public abstract bool Exists(Dictionary<string, object> values, string tableName, string connectionString = "");
        /// <summary>
        /// 判断指定表指定栏位值是否存在
        /// </summary>
        /// <param name="list">栏位名称/值</param>
        /// <param name="tableName"></param>
        /// <param name="userMasterConnection">是否使用主数据库进行查询</param>
        /// <returns></returns>
        public bool Exists(List<Utility.DBUtility.CustomParameter> list, string tableName, bool userMasterConnection)
        {
            if (userMasterConnection)
            {
                return Exists(list, tableName, m_WriteConnectionString);
            }
            return Exists(list, tableName);
        }
        /// <summary>
        /// 判断指定表指定栏位值是否存在
        /// </summary>
        /// <param name="list">栏位名称/值</param>
        /// <param name="tableName"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public abstract bool Exists(List<Utility.DBUtility.CustomParameter> list, string tableName, string connectionString = "");
        /// <summary>
        /// 删除指定表数据
        /// </summary>
        /// <param name="values"></param>
        /// <param name="tableName"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public abstract int Delete(Dictionary<string, object> values, string tableName, string connectionString = "");
        /// <summary>
        /// 删除指定表数据
        /// </summary>
        /// <param name="list"></param>
        /// <param name="tableName"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public abstract int Delete(List<Utility.DBUtility.CustomParameter> list, string tableName, string connectionString = "");
        /// <summary>
        /// 判断指定表指定栏位值是否存在
        /// </summary>
        /// <param name="column">列名</param>
        /// <param name="value">值</param>
        /// <param name="tableName">表名</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public abstract bool Exists(string column, dynamic value, string tableName, string connectionString = "");
        #endregion

        #region ExecuteSql/ExecuteScalar/ExecuteReader
        /// <summary>
        /// 执行SQL语句，返回影响的记录数
        /// </summary>
        /// <param name="strSql">SQL语句</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>影响的记录数</returns>
        public int ExecuteSql(string strSql, string connectionString = "")
        {
            return ExecuteSql(strSql, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 执行多条SQL语句，实现数据库事务。
        /// </summary>
        /// <param name="strSqlList">多条SQL语句</param>  
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>  
        public abstract int ExecuteSqlTran(List<string> strSqlList, string connectionString = "");
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>查询结果</returns>
        public T ExecuteScalar<T>(string strSql, string connectionString = "")
        {
            return ExecuteScalar<T>(strSql, string.Empty, m_NullParameter);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="userMasterConnection">是否使用主数据库进行查询</param>
        /// <returns>查询结果</returns>
        public T ExecuteScalar<T>(string strSql, bool userMasterConnection)
        {
            if (userMasterConnection)
            {
                return ExecuteScalar<T>(strSql, m_WriteConnectionString);
            }
            return ExecuteScalar<T>(strSql);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="userMasterConnection">是否使用主数据库进行查询</param>
        /// <returns>查询结果</returns>
        public object ExecuteScalar(string strSql, bool userMasterConnection)
        {
            if (userMasterConnection)
            {
                return ExecuteScalar(strSql, m_WriteConnectionString);
            }
            return ExecuteScalar(strSql);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果（object）。
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public object ExecuteScalar(string strSql, string connectionString = "")
        {
            return ExecuteScalar(strSql, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 执行查询语句，返回OracleDataReader ( 注意：调用该方法后，一定要对IDataReader进行Close )
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="userMasterConnection">是否使用主数据库进行查询</param>
        /// <returns></returns>
        public IDataReader ExecuteReader(string strSql, bool userMasterConnection)
        {
            if (userMasterConnection)
            {
                return ExecuteReader(strSql, m_WriteConnectionString);
            }
            return ExecuteReader(strSql);
        }
        /// <summary>
        /// 执行查询语句，返回OracleDataReader ( 注意：调用该方法后，一定要对IDataReader进行Close )
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public IDataReader ExecuteReader(string strSql, string connectionString = "")
        {
            return ExecuteReader(strSql, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 获取指定表指定栏位的记录数
        /// </summary>
        /// <param name="column"></param>
        /// <param name="value"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public int GetCountByColumn(string column, dynamic value, string tableName)
        {
            return GetCountByColumn(column, value, tableName, string.Empty);
        }
        /// <summary>
        /// 获取指定表指定栏位的记录数
        /// </summary>
        /// <param name="column"></param>
        /// <param name="value"></param>
        /// <param name="tableName"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public abstract int GetCountByColumn(string column, dynamic value, string tableName, string connectionString = "");

        #region 执行带参数的SQL语句
        /// <summary>
        /// 执行SQL语句，返回影响的记录数
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public int ExecuteSql(string strSql, params DBParameter[] cmdParms)
        {
            return ExecuteSql(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行SQL语句，返回影响的记录数
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public int ExecuteSql(string strSql, params IDataParameter[] cmdParms)
        {
            return ExecuteSql(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行SQL语句，返回影响的记录数
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="userMasterConnection">是否使用主数据库进行查询</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public int ExecuteSql(string strSql, bool userMasterConnection, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return ExecuteSql(strSql, m_WriteConnectionString, cmdParms);
            }
            return ExecuteSql(strSql, cmdParms);
        }
        /// <summary>
        /// 执行SQL语句，返回影响的记录数
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public int ExecuteSql(string strSql, string connectionString = "", params DBParameter[] cmdParms)
        {
            return ExecuteSql(strSql, connectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 执行SQL语句，返回影响的记录数
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="userMasterConnection">是否使用主数据库进行查询</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public int ExecuteSql(string strSql, bool userMasterConnection, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return ExecuteSql(strSql, m_WriteConnectionString, cmdParms);
            }
            return ExecuteSql(strSql, cmdParms);
        }
        /// <summary>
        /// 执行SQL语句，返回影响的记录数
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public abstract int ExecuteSql(string strSql, string connectionString = "", params IDataParameter[] cmdParms);
        /// <summary>
        /// 执行多条SQL语句，实现数据库事务。
        /// </summary>
        /// <param name="strSqlList">SQL语句的哈希表（key为sql语句，value是该语句的IDataParameter[]）</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public abstract int ExecuteSqlTran(List<ExcuteSqlParameters> strSqlList, string connectionString = "");
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="cmdParms"></param>
        /// <returns>查询结果</returns>
        public T ExecuteScalar<T>(string strSql,bool userMasterConnection,  params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return ExecuteScalar<T>(strSql, m_WriteConnectionString, cmdParms);
            }
            return ExecuteScalar<T>(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="cmdParms"></param>
        /// <returns>查询结果</returns>
        public T ExecuteScalar<T>(string strSql, params DBParameter[] cmdParms)
        {
            return ExecuteScalar<T>(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="cmdParms"></param>
        /// <returns>查询结果</returns>
        public T ExecuteScalar<T>(string strSql, bool userMasterConnection, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return ExecuteScalar<T>(strSql, m_WriteConnectionString, cmdParms);
            }
            return ExecuteScalar<T>(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="cmdParms"></param>
        /// <returns>查询结果</returns>
        public T ExecuteScalar<T>(string strSql, params IDataParameter[] cmdParms)
        {
            return ExecuteScalar<T>(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns>查询结果</returns>
        public T ExecuteScalar<T>(string strSql, string connectionString = "", params DBParameter[] cmdParms)
        {
            return ExecuteScalar<T>(strSql, connectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns>查询结果</returns>
        public T ExecuteScalar<T>(string strSql, string connectionString = "", params IDataParameter[] cmdParms)
        {
            object obj = ExecuteScalar(strSql, connectionString, cmdParms);
            if (obj != null)
            {
                return (T)Convert.ChangeType(obj, typeof(T));
            }
            else
            {
                return default(T);
            }
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="cmdParms"></param>
        /// <returns>查询结果</returns>
        public object ExecuteScalar(string strSql, bool userMasterConnection, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return ExecuteScalar(strSql, m_WriteConnectionString, cmdParms);
            }
            return ExecuteScalar(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果
        /// </summary>
        /// <param name="strSql">计算查询结果语句</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="cmdParms"></param>
        /// <returns>查询结果</returns>
        public object ExecuteScalar(string strSql, bool userMasterConnection, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return ExecuteScalar(strSql, m_WriteConnectionString, cmdParms);
            }
            return ExecuteScalar(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果（object）。
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public object ExecuteScalar(string strSql, params DBParameter[] cmdParms)
        {
            return ExecuteScalar(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果（object）。
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public object ExecuteScalar(string strSql, params IDataParameter[] cmdParms)
        {
            return ExecuteScalar(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果（object）。
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public object ExecuteScalar(string strSql, string connectionString = "", params DBParameter[] cmdParms)
        {
            return ExecuteScalar(strSql, connectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 执行一条计算查询结果语句，返回查询结果（object）。
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public abstract object ExecuteScalar(string strSql, string connectionString = "", params IDataParameter[] cmdParms);
        /// <summary>
        /// 执行查询语句，返回OracleDataReader ( 注意：调用该方法后，一定要对IDataReader进行Close )
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="userMasterConnection">使用主库查询</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public IDataReader ExecuteReader(string strSql, bool userMasterConnection, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return ExecuteReader(strSql, m_WriteConnectionString, cmdParms);
            }
            return ExecuteReader(strSql,string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回OracleDataReader ( 注意：调用该方法后，一定要对IDataReader进行Close )
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="userMasterConnection">使用主库查询</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public IDataReader ExecuteReader(string strSql, bool userMasterConnection, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return ExecuteReader(strSql, m_WriteConnectionString, cmdParms);
            }
            return ExecuteReader(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回OracleDataReader ( 注意：调用该方法后，一定要对IDataReader进行Close )
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public IDataReader ExecuteReader(string strSql, params DBParameter[] cmdParms)
        {
            return ExecuteReader(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回OracleDataReader ( 注意：调用该方法后，一定要对IDataReader进行Close )
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public IDataReader ExecuteReader(string strSql, string connectionString = "", params DBParameter[] cmdParms)
        {
            return ExecuteReader(strSql, connectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 执行查询语句，返回OracleDataReader ( 注意：调用该方法后，一定要对IDataReader进行Close )
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public IDataReader ExecuteReader(string strSql, params IDataParameter[] cmdParms)
        {
            return ExecuteReader(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回OracleDataReader ( 注意：调用该方法后，一定要对IDataReader进行Close )
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public abstract IDataReader ExecuteReader(string strSql, string connectionString = "", params IDataParameter[] cmdParms);
        #endregion

        #endregion

        #region Query
        /// <summary>
        /// 执行查询语句，返回DataTable
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns></returns>
        public DataTable Query(string strSql, bool userMasterConnection)
        {
            if (userMasterConnection)
            {
                return Query(strSql, m_WriteConnectionString);
            }
            return Query(strSql);
        }
        /// <summary>
        /// 执行查询语句，返回DataTable
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public DataTable Query(string strSql, string connectionString = "")
        {
            return Query(strSql, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 执行查询语句，返回DataSet
        /// </summary>
        /// <typeparam name="TKey">TKey</typeparam>
        /// <typeparam name="TValue">TValue</typeparam>
        /// <param name="strSql">strSql</param>
        /// <param name="columnName">需要作为Tkey主键的栏位</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>DataSet</returns>
        public Dictionary<TKey, TValue> Query<TKey, TValue>(string strSql, string columnName, bool userMasterConnection)
        {
            if (userMasterConnection)
            {
                return Query<TKey, TValue>(strSql, columnName, m_WriteConnectionString);
            }
            return Query<TKey, TValue>(strSql, columnName);
        }
        /// <summary>
        /// 执行查询语句，返回DataSet
        /// </summary>
        /// <typeparam name="TKey">TKey</typeparam>
        /// <typeparam name="TValue">TValue</typeparam>
        /// <param name="strSql">strSql</param>
        /// <param name="columnName">需要作为Tkey主键的栏位</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>DataSet</returns>
        public Dictionary<TKey, TValue> Query<TKey, TValue>(string strSql, string columnName, string connectionString = "")
        {
            return Query<TKey, TValue>(strSql, columnName, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 执行查询语句，返回DataTable
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public DataTable Query(string strSql, bool userMasterConnection, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query(strSql, m_WriteConnectionString, cmdParms);
            }
            return Query(strSql,string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回DataTable
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public DataTable Query(string strSql, params DBParameter[] cmdParms)
        {
            return Query(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回DataTable
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public DataTable Query(string strSql, bool userMasterConnection, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query(strSql, m_WriteConnectionString, cmdParms);
            }
            return Query(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回DataTable
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public DataTable Query(string strSql, params IDataParameter[] cmdParms)
        {
            return Query(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回DataTable
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public DataTable Query(string strSql, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query(strSql, connectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 执行查询语句，返回DataTable
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms"></param>
        /// <returns></returns>
        public abstract DataTable Query(string strSql, string connectionString = "", params IDataParameter[] cmdParms);
        /// <summary>
        /// 执行查询语句，返回List[T]
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <typeparam name="T">entity</typeparam>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>DataSet</returns>
        public List<T> Query<T>(string strSql, bool userMasterConnection)
        {
            if (userMasterConnection)
            {
                return Query<T>(strSql, m_WriteConnectionString);
            }
            return Query<T>(strSql);
        }
        /// <summary>
        /// 执行查询语句，返回List[T]
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <typeparam name="T">entity</typeparam>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>DataSet</returns>
        public List<T> Query<T>(string strSql, string connectionString = "")
        {
            return Query<T>(strSql, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 执行查询语句,返回Json格式字符串List
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns></returns>
        public string Query4Json(string strSql, bool userMasterConnection)
        {
            if (userMasterConnection)
            {
                return Query4Json(strSql, m_WriteConnectionString);
            }
            return Query4Json(strSql);
        }
        /// <summary>
        /// 执行查询语句,返回Json格式字符串List
        /// </summary>
        /// <param name="strSql"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public string Query4Json(string strSql, string connectionString = "")
        {
            return Query4Json(strSql, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <typeparam name="TKey">TKey</typeparam>
        /// <typeparam name="TValue">TValue</typeparam>
        /// <param name="strSql">strSql</param>
        /// <param name="columnName">需要作为Tkey主键的栏位</param>
        /// <param name="cmdParms"></param>
        /// <returns>DataSet</returns>
        public Dictionary<TKey, TValue> Query<TKey, TValue>(string strSql, string columnName, params DBParameter[] cmdParms)
        {
            return Query<TKey, TValue>(strSql, columnName, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <typeparam name="TKey">TKey</typeparam>
        /// <typeparam name="TValue">TValue</typeparam>
        /// <param name="strSql">str Sql</param>
        /// <param name="columnName">column Name</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public Dictionary<TKey, TValue> Query<TKey, TValue>(string strSql, string columnName, params IDataParameter[] cmdParms)
        {
            return Query<TKey, TValue>(strSql, columnName, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <typeparam name="TKey">TKey</typeparam>
        /// <typeparam name="TValue">TValue</typeparam>
        /// <param name="strSql">str Sql</param>
        /// <param name="columnName">需要作为Tkey主键的栏位</param>
        /// <param name="userMasterConnection">使用主库查询</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public Dictionary<TKey, TValue> Query<TKey, TValue>(string strSql, string columnName,bool userMasterConnection, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query<TKey, TValue>(strSql, columnName, m_WriteConnectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
            }
            return Query<TKey, TValue>(strSql, columnName, string.Empty, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <typeparam name="TKey">TKey</typeparam>
        /// <typeparam name="TValue">TValue</typeparam>
        /// <param name="strSql">str Sql</param>
        /// <param name="columnName">需要作为Tkey主键的栏位</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public Dictionary<TKey, TValue> Query<TKey, TValue>(string strSql, string columnName, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query<TKey, TValue>(strSql, columnName, connectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <typeparam name="TKey">TKey</typeparam>
        /// <typeparam name="TValue">TValue</typeparam>
        /// <param name="strSql">str Sql</param>
        /// <param name="columnName">需要作为Tkey主键的栏位</param>
        /// <param name="userMasterConnection">使用主库查询</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public Dictionary<TKey, TValue> Query<TKey, TValue>(string strSql, string columnName, bool userMasterConnection, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query<TKey, TValue>(strSql, columnName, m_WriteConnectionString, cmdParms);
            }
            return Query<TKey, TValue>(strSql, columnName, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <typeparam name="TKey">TKey</typeparam>
        /// <typeparam name="TValue">TValue</typeparam>
        /// <param name="strSql">str Sql</param>
        /// <param name="columnName">需要作为Tkey主键的栏位</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public Dictionary<TKey, TValue> Query<TKey, TValue>(string strSql, string columnName, string connectionString = "", params IDataParameter[] cmdParms)
        {
            return Query(strSql, connectionString, cmdParms).DataToDictionary<TKey, TValue>(columnName);
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <typeparam name="T">entity</typeparam>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public List<T> Query<T>(string strSql, bool userMasterConnection, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query<T>(strSql, m_WriteConnectionString, cmdParms);
            }
            return Query<T>(strSql, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回List[T]
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <typeparam name="T">entity</typeparam>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public List<T> Query<T>(string strSql, params DBParameter[] cmdParms)
        {
            return Query<T>(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <typeparam name="T">entity</typeparam>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public List<T> Query<T>(string strSql, bool userMasterConnection, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query<T>(strSql, m_WriteConnectionString, cmdParms);
            }
            return Query<T>(strSql, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回List[T]
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <typeparam name="T">entity</typeparam>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public List<T> Query<T>(string strSql, params IDataParameter[] cmdParms)
        {
            return Query<T>(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <typeparam name="T">entity</typeparam>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public List<T> Query<T>(string strSql, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query<T>(strSql, connectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 执行查询语句，返回List[T]
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <typeparam name="T">entity</typeparam>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public List<T> Query<T>(string strSql, string connectionString = "", params IDataParameter[] cmdParms)
        {
            return Query(strSql, connectionString, cmdParms).ToList<T>();
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public string Query4Json(string strSql, bool userMasterConnection, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query4Json(strSql, m_WriteConnectionString, cmdParms);
            }
            return Query4Json(strSql, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回Json 格式数据list
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public string Query4Json(string strSql, params DBParameter[] cmdParms)
        {
            return Query4Json(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns>DataSet</returns>
        public string Query4Json(string strSql, bool userMasterConnection, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query4Json(strSql, m_WriteConnectionString, cmdParms);
            }
            return Query4Json(strSql, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回Json 格式数据list
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="cmdParms">查询参数</param>
        /// <returns></returns>
        public string Query4Json(string strSql, params IDataParameter[] cmdParms)
        {
            return Query4Json(strSql, string.Empty, cmdParms);
        }
        /// <summary>
        /// 执行查询语句，返回Json 格式数据list
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="cmdParms">查询参数</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>DataSet</returns>
        public string Query4Json(string strSql, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query4Json(strSql, connectionString, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 执行查询语句，返回Json 格式数据list
        /// </summary>
        /// <param name="strSql">strSql</param>
        /// <param name="cmdParms">查询参数</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>DataSet</returns>
        public string Query4Json(string strSql, string connectionString = "", params IDataParameter[] cmdParms)
        {
            return Query(strSql, connectionString, cmdParms).DataToJsonList();
        }
        #region 执行分页查询

        #region 分页返回DataTable
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql,bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20)
        {
            if (userMasterConnection)
            {
                return Query(strSql, out totalCount,pageIndex,pageSize, m_WriteConnectionString);
            }
            return Query(strSql, out totalCount, pageIndex, pageSize);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "")
        {
            return Query(string.Empty, strSql, out totalCount, pageIndex, pageSize, connectionString);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20)
        {
            return Query(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query(string.Empty, strSql, userMasterConnection, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query(string.Empty, strSql, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query(string.Empty, strSql, userMasterConnection, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query(string.Empty, strSql, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query(string.Empty, strSql, out totalCount, pageIndex, pageSize, connectionString, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params IDataParameter[] cmdParms)
        {
            return Query(string.Empty, strSql, out totalCount, pageIndex, pageSize, connectionString, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        #endregion

        #region 分页返回List<T>
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns></returns>
        public List<T> Query<T>(string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20)
        {
            if (userMasterConnection)
            {
                return Query<T>(strSql, out totalCount, pageIndex, pageSize, m_WriteConnectionString);
            }
            return Query<T>(strSql, out totalCount, pageIndex, pageSize, string.Empty);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <returns></returns>
        public List<T> Query<T>(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "")
        {
            return Query<T>(string.Empty, strSql, out totalCount, pageIndex, pageSize, connectionString);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <returns></returns>
        public List<T> Query<T>(string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20)
        {
            return Query<T>(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query<T>(string.Empty, strSql,userMasterConnection ,out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query<T>(string.Empty, strSql, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query<T>(string.Empty, strSql, userMasterConnection, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query<T>(string.Empty, strSql, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query<T>(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query<T>(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params IDataParameter[] cmdParms)
        {
            return Query<T>(string.Empty, strSql, out totalCount, pageIndex, pageSize, connectionString, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query<T>(string.Empty, strSql, out totalCount, pageIndex, pageSize, connectionString, cmdParms);
        }
        #endregion

        #region 分页查询返回Json
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "")
        {
            return Query4Json(string.Empty, strSql, out totalCount, pageIndex, pageSize, connectionString);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20)
        {
            return Query4Json(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query4Json(string.Empty, strSql, userMasterConnection, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query4Json(string.Empty, strSql, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query4Json(string.Empty, strSql, userMasterConnection, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query4Json(string.Empty, strSql, out totalCount, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query4Json(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params IDataParameter[] cmdParms)
        {
            return Query4Json(string.Empty, strSql, out totalCount, pageIndex, pageSize, connectionString, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query4Json(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query4Json(string.Empty, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        #endregion

        #region 带前缀分页返回DataTable
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20)
        {
            if (userMasterConnection)
            {
                return Query(prefixSql, strSql, out totalCount, m_WriteConnectionString, pageIndex, pageSize, m_NullParameter);
            }
            return Query(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, m_NullParameter);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "")
        {
            return Query(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, m_NullParameter);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20)
        {
            return Query(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, m_NullParameter);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query(prefixSql, strSql, out totalCount, m_WriteConnectionString, pageIndex, pageSize, cmdParms);
            }
            return Query(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query(prefixSql, strSql, out totalCount, m_WriteConnectionString, pageIndex, pageSize, cmdParms);
            }
            return Query(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params IDataParameter[] cmdParms)
        {
            return Query(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public DataTable Query(string prefixSql, string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>
        /// <param name="totalCount">总数据行(total Count)</param>
        /// <param name="pageIndex">第几页(page Index)</param>
        /// <param name="pageSize">每页的数据行数(page Size)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>Data Table</returns>
        public abstract DataTable Query(string prefixSql, string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms);
        #endregion

        #region 带前缀分页返回List<T>
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <returns></returns>
        public List<T> Query<T>(string prefixSql, string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20)
        {
            if (userMasterConnection)
            {
                return Query<T>(prefixSql, strSql, out totalCount, pageIndex, pageSize, m_WriteConnectionString, m_NullParameter);
            }
            return Query<T>(prefixSql, strSql, out totalCount, pageIndex, pageSize, string.Empty, m_NullParameter);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <returns></returns>
        public List<T> Query<T>(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "")
        {
            return Query<T>(prefixSql, strSql, out totalCount, pageIndex, pageSize, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <returns></returns>
        public List<T> Query<T>(string prefixSql, string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20)
        {
            return Query<T>(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, m_NullParameter);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string prefixSql, string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query<T>(prefixSql, strSql, out totalCount,m_WriteConnectionString, pageIndex, pageSize, cmdParms);
            }
            return Query<T>(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query<T>(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string prefixSql, string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query<T>(prefixSql, strSql, out totalCount, m_WriteConnectionString, pageIndex, pageSize, cmdParms);
            }
            return Query<T>(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query<T>(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string prefixSql, string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms).ToList<T>();
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string prefixSql, string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query<T>(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params IDataParameter[] cmdParms)
        {
            return Query<T>(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public List<T> Query<T>(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query<T>(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        #endregion

        #region 带前缀分页查询返回Json
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20)
        {
            if (userMasterConnection)
            {
                return Query4Json(prefixSql, strSql, out totalCount, m_WriteConnectionString, pageIndex, pageSize);
            }
            return Query4Json(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "")
        {
            return Query4Json(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20)
        {
            return Query4Json(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, m_NullParameter);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query4Json(prefixSql, strSql, out totalCount, m_WriteConnectionString, pageIndex, pageSize, cmdParms);
            }
            return Query4Json(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query4Json(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <param name="userMasterConnection">是否使用主库进行查询</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, bool userMasterConnection, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            if (userMasterConnection)
            {
                return Query4Json(prefixSql, strSql, out totalCount, m_WriteConnectionString, pageIndex, pageSize, cmdParms);
            }
            return Query4Json(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query4Json(prefixSql, strSql, out totalCount, string.Empty, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params DBParameter[] cmdParms)
        {
            return Query4Json(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, out int totalCount, int pageIndex = 1, int pageSize = 20, string connectionString = "", params IDataParameter[] cmdParms)
        {
            return Query4Json(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params DBParameter[] cmdParms)
        {
            return Query4Json(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar));
        }
        /// <summary>
        /// 分页查询
        /// Paging query
        /// </summary>
        /// <param name="prefixSql">前缀SQL</param>
        /// <param name="strSql">
        /// 需要执行分页的SQL
        /// [如果Sql中带排序字段,则排序字段必须出现再Select的字段中,并且程序会自动将Sql中的排序作为查询的排序]
        /// </param>        
        /// <param name="totalCount">总数据行(totalCount)</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="pageIndex">第几页(pageIndex)</param>
        /// <param name="pageSize">每页的数据行数(pageSize)</param>
        /// <param name="cmdParms">查询参数(cmdParms)</param>
        /// <returns>List</returns>
        public string Query4Json(string prefixSql, string strSql, out int totalCount, string connectionString, int pageIndex = 1, int pageSize = 20, params IDataParameter[] cmdParms)
        {
            return Query(prefixSql, strSql, out totalCount, connectionString, pageIndex, pageSize, cmdParms).ToJsonList();
        }
        #endregion

        #endregion

        #endregion

        #region 存储过程操作
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="tableName">DataSet结果中的表名</param>
        /// <returns>DataSet</returns>
        public DataSet RunProcedure(string storedProcName, string tableName, string connectionString = "")
        {
            return RunProcedure(storedProcName, tableName, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="tableName">DataSet结果中的表名</param>
        /// <returns>DataSet</returns>
        public DataSet RunProcedure(string storedProcName, string tableName, string connectionString = "", params DBParameter[] parameters)
        {
            var ps = parameters.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar);
            DataSet ds = RunProcedure(storedProcName, tableName, connectionString, ps);
            for (int i = 0; null != parameters && i < ps.Length; i++)
            {
                parameters[i].Value = ps[i].Value;
            }
            return ds;
        }
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="tableName">DataSet结果中的表名</param>
        /// <returns>DataSet</returns>
        public abstract DataSet RunProcedure(string storedProcName, string tableName, string connectionString = "", params IDataParameter[] parameters);
        /// <summary>
        /// 执行存储过程，返回影响的行数    
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="rowsAffected">影响的行数</param>
        /// <returns></returns>
        public int RunProcedure(string storedProcName, out int rowsAffected, string connectionString = "")
        {
            return RunProcedure(storedProcName, out rowsAffected, connectionString, m_NullParameter);
        }
        /// <summary>
        /// 执行存储过程，返回影响的行数    
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <param name="rowsAffected">影响的行数</param>
        /// <returns></returns>
        public int RunProcedure(string storedProcName, DBParameter[] parameters, out int rowsAffected)
        {
            var ps = parameters.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar);
            int count = RunProcedure(storedProcName, out rowsAffected, string.Empty, ps);
            for (int i = 0; null != parameters && i < ps.Length; i++)
            {
                parameters[i].Value = ps[i].Value;
            }
            return count;
        }
        /// <summary>
        /// 执行存储过程，返回影响的行数    
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <param name="rowsAffected">影响的行数</param>
        /// <returns></returns>
        public int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected)
        {
            return RunProcedure(storedProcName, out rowsAffected, string.Empty, parameters);
        }
        /// <summary>
        /// 执行存储过程，返回影响的行数    
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <param name="rowsAffected">影响的行数</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public int RunProcedure(string storedProcName, out int rowsAffected, string connectionString = "", params DBParameter[] parameters)
        {
            var ps = parameters.ToDataParameter(m_DatabaseType, m_DataParamterPrefixChar);
            int count = RunProcedure(storedProcName, out rowsAffected, connectionString, ps);
            for (int i = 0; null != parameters && i < ps.Length; i++)
            {
                parameters[i].Value = ps[i].Value;
            }
            return count;
        }
        /// <summary>
        /// 执行存储过程，返回影响的行数    
        /// </summary>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <param name="rowsAffected">影响的行数</param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public abstract int RunProcedure(string storedProcName, out int rowsAffected, string connectionString = "", params IDataParameter[] parameters);
        #endregion

        #region OracleBulkCopy
        /// <summary>
        /// 批量导入数据
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="tableName"></param>
        /// <param name="disposeTable">是否销毁表,如果为false,则自动清空表数据</param>
        /// <returns></returns>
        public bool BulkCopy(DataTable dt, string tableName, bool disposeTable = true)
        {
            return BulkCopy(dt, tableName, string.Empty, disposeTable);
        }
        /// <summary>
        /// 批量导入数据
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="tableName"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="disposeTable">是否销毁表,如果为false,则自动清空表数据</param>
        /// <returns></returns>
        public abstract bool BulkCopy(DataTable dt, string tableName, string connectionString, bool disposeTable = true);

        /// <summary>
        /// 批量导入数据
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="tableName"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public abstract bool BulkCopy(IDataReader reader, string tableName, string connectionString = "");

        /// <summary>
        /// 批量导入数据
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="tableName"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public bool BulkCopy(DataRow[] rows, string tableName, string connectionString = "")
        {
            if (null == rows || rows.Length == 0)
            {
                return true;
            }
            DataTable dt = rows.CreateDataTable();
            for (int i = 0; i < rows.Length; i++)
            {
                dt.Rows.Add(rows[i]);
            }
            return BulkCopy(dt, DataRowState.Added, tableName, connectionString, true);
        }
        /// <summary>
        /// 批量导入数据
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="rowState"></param>
        /// <param name="tableName"></param>
        /// <param name="disposeTable">是否销毁表</param>
        /// <returns></returns>
        public bool BulkCopy(DataTable dt, DataRowState rowState, string tableName, bool disposeTable = true)
        {
            return BulkCopy(dt, rowState, tableName, string.Empty, disposeTable);
        }
        /// <summary>
        /// 批量导入数据
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="rowState">需要写入到DB的Row状态</param>
        /// <param name="tableName"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <param name="disposeTable">是否销毁表</param>
        /// <returns></returns>
        public abstract bool BulkCopy(DataTable dt, DataRowState rowState, string tableName, string connectionString, bool disposeTable = true);
        /// <summary>
        /// 使用DataAdapter进行批量提交Insert,Update,Delete
        /// 如果使用Delete, DataTable中Row需要使用 Delete进行删除,不能使用Remove|RemoveAt进行移除,因为Delete只是注释数据行的状态
        /// 使用DataAdapter必须要求有主键
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public int DataAdapter(DataTable dt, string connectionString = "")
        {
            return DataAdapter(dt, dt.TableName, DataRowState.Modified, connectionString);
        }
        /// <summary>
        /// 使用DataAdapter进行批量提交Insert,Update,Delete
        /// 如果使用Delete, DataTable中Row需要使用 Delete进行删除,不能使用Remove|RemoveAt进行移除,因为Delete只是注释数据行的状态
        /// 使用DataAdapter必须要求有主键
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="tableName"></param>
        /// <param name="unchangedDefaultState">
        /// 表结构中, Unchanged状态的Row 默认设置为哪种状态
        /// </param>
        /// <param name="connectionString">数据库链接字符串(为空则使用默认连接字符串)</param>
        /// <returns></returns>
        public abstract int DataAdapter(DataTable dt, string tableName, DataRowState unchangedDefaultState = DataRowState.Modified, string connectionString = "");
        #endregion
    }
}
